/*
 * This file is part of Shopping Lists Organizer software
 *
 * Copyright (C) 2011 Denis Kvita <dkvita@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include <QtGui>
#include "lockcodeinputdlg.h"

lockCodeInputDlg::lockCodeInputDlg(QWidget *parent) :
	QDialog(parent)
{
	setWindowTitle(tr("Lock"));
	QLabel *l= new QLabel(tr("Enter code:"));
	l->setAlignment(Qt::AlignRight);
	pwdLe= new QLineEdit;
	pwdLe->setEchoMode(QLineEdit::Password);

	QHBoxLayout *pLt= new QHBoxLayout;
	pLt->addWidget(l);
	pLt->addWidget(pwdLe,1);
	pLt->setMargin(0);

	QPushButton *ok= new QPushButton(tr("Ok"));
	connect(ok, SIGNAL(clicked()), this, SLOT(accept()));

	QPushButton *cnl= new QPushButton(tr("Cancel"));
	connect(cnl, SIGNAL(clicked()), this, SLOT(reject()));

	QHBoxLayout *clt= new QHBoxLayout;
	clt->addStretch(1);
	clt->addWidget(ok);
	clt->addStretch(1);
	clt->addWidget(cnl);
	clt->addStretch(1);

	QVBoxLayout *mlt= new QVBoxLayout;
	mlt->addLayout(pLt);
	mlt->addStretch(1);
	mlt->addLayout(clt);

	setLayout(mlt);
}

void lockCodeInputDlg::accept()
{
	if(pwdLe->text().length() < 4){
		QToolTip::showText(mapToGlobal(pwdLe->pos()),tr("The lock code must be at least 4 chars!"));
		return;
	}
	QDialog::accept();
}
